package com.devin.controller;

import com.devin.pojo.LogLogin;
import com.devin.service.LogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/logs")
public class LogController {
    @Autowired
    private LogService logService;

    @RequestMapping("/getLogs")
    public ModelAndView findLogs(@RequestParam(value = "page",defaultValue = "1")Integer page,
                                 @RequestParam(value = "size",defaultValue = "5")Integer size){
        List<LogLogin> logs = logService.findLogs(page,size);
        PageInfo<LogLogin> logLoginPageInfo = new PageInfo<LogLogin>(logs);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("logLoginPageInfo",logLoginPageInfo);
        modelAndView.setViewName("log-pages-list");
        return modelAndView;
    }

    @RequestMapping("/delLog")
    public String delLogById(@RequestParam("logId") Integer id){
        logService.delLogById(id);
        return "redirect:/logs/getLogs";
    }
}
